<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:pom="http://www.pomodorotechnique.com/server">
	<xsl:param name="username" />
	<xsl:param name="year" />
	<xsl:param name="month" />
	<xsl:template match="/pom:users">
		<xsl:for-each select="pom:user[@id = $username]">
			<pom:plans>
				<xsl:choose>
					<xsl:when test="$year and $month">
						<xsl:for-each select="pom:plan[substring(@date,1,4) = $year and substring(@date,6,2) = $month]">
							<xsl:apply-templates select="." />
						</xsl:for-each>
					</xsl:when>
					<xsl:otherwise>
						<xsl:choose>
							<xsl:when test="$year">
								<xsl:for-each select="pom:plan[substring(@date,1,4) = $year]">
									<xsl:apply-templates select="." />
								</xsl:for-each>
							</xsl:when>
							<xsl:otherwise>
								<xsl:for-each select="pom:plan">
									<xsl:apply-templates select="." />
								</xsl:for-each>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:otherwise>
				</xsl:choose>
			</pom:plans>
		</xsl:for-each>
	</xsl:template>

	<xsl:template match="pom:plan">
		<pom:plan>
			<xsl:attribute name="date"><xsl:value-of select="@date" /></xsl:attribute>
			<xsl:attribute name="status"><xsl:value-of select="@status" /></xsl:attribute>
		</pom:plan>
	</xsl:template>
</xsl:stylesheet>